package com.zys.el.user.quartz;

import com.alibaba.fastjson.JSON;
import com.zys.el.user.config.po.Start;
import com.zys.el.user.po.TargetUser;
import com.zys.el.user.po.User;
import com.zys.el.user.service.ISynthesizeService;
import com.zys.el.user.service.ITargetService;
import com.zys.el.user.service.ITargetUserService;
import com.zys.el.user.service.IUserService;
import lombok.SneakyThrows;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.quartz.QuartzJobBean;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

public class FinnishedQuartz extends QuartzJobBean {
    @Resource
    private ITargetService service;
    @Resource
    private IUserService userService;
    @Resource
    private RedisTemplate redisTemplate;
    @Resource
    private ITargetUserService targetUserService;


    @SneakyThrows
    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {

        System.out.println("各用户完成度数据加载开始！！！");
        List<User> list = userService.list();
        for (User user : list) {
           Long userId = user.getId();

            TargetUser targetUser = targetUserService.selectTargetByUserId(userId);
            Long targetId = targetUser.getTargetId();
            Start start = service.finishedTargetProcess(userId, targetId);

            redisTemplate.opsForValue().set("FN" +user.getId(), JSON.toJSONString(start));

        }

//        System.out.println("各用户完成度数据加载结束！！！");
    }
}
